package com.edu.exam.entity.quality.workflow;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Comment;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 审核任务实体类
 * 对应数据库表：audit_task
 *
 * 根据B-02-05试题审核流程子模块设计文档实现
 * 管理审核任务信息，支持人工审核和跳过审核两种任务类型。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Table(name = "audit_task")
@Comment("审核任务表")
@EntityListeners(AuditingEntityListener.class)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AuditFlowTask {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    /**
     * 审核任务唯一标识符
     */
    @NotBlank(message = "审核任务ID不能为空")
    @Size(max = 50, message = "审核任务ID长度不能超过50个字符")
    @Column(name = "task_id", nullable = false, length = 50, unique = true)
    private String taskId;

    /**
     * 关联的审核流程实例ID
     */
    @NotBlank(message = "审核流程实例ID不能为空")
    @Size(max = 50, message = "审核流程实例ID长度不能超过50个字符")
    @Column(name = "instance_id", nullable = false, length = 50)
    private String instanceId;

    /**
     * 关联的审核环节ID
     */
    @Size(max = 50, message = "审核环节ID长度不能超过50个字符")
    @Column(name = "step_id", length = 50)
    private String stepId;

    /**
     * 审核任务类型（1-人工审核，2-跳过审核）
     */
    @NotNull(message = "审核任务类型不能为空")
    @Column(name = "task_type", nullable = false)
    private Integer taskType;

    /**
     * 审核任务状态（PENDING-待处理，IN_PROGRESS-处理中，COMPLETED-已完成，CANCELLED-已取消，TIMEOUT-已超时）
     */
    @NotBlank(message = "审核任务状态不能为空")
    @Size(max = 20, message = "审核任务状态长度不能超过20个字符")
    @Column(name = "task_status", nullable = false, length = 20)
    private String taskStatus;

    /**
     * 审核人员ID
     */
    @Size(max = 50, message = "审核人员ID长度不能超过50个字符")
    @Column(name = "auditor_id", length = 50)
    private String auditorId;

    /**
     * 审核人员姓名
     */
    @Size(max = 100, message = "审核人员姓名长度不能超过100个字符")
    @Column(name = "auditor_name", length = 100)
    private String auditorName;

    /**
     * 优先级（1-最高，依次递减）
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 分配时间
     */
    @Column(name = "assign_time")
    private LocalDateTime assignTime;

    /**
     * 开始处理时间
     */
    @Column(name = "start_time")
    private LocalDateTime startTime;

    /**
     * 完成时间
     */
    @Column(name = "complete_time")
    private LocalDateTime completeTime;

    /**
     * 预计完成时间
     */
    @Column(name = "estimated_completion_time")
    private LocalDateTime estimatedCompletionTime;

    /**
     * 审核评分（0-100分）
     */
    @Column(name = "audit_score", precision = 5, scale = 2)
    private BigDecimal auditScore;

    /**
     * 审核权重
     */
    @Column(name = "audit_weight", precision = 5, scale = 2)
    private BigDecimal auditWeight;

    /**
     * 审核意见
     */
    @Column(name = "audit_comment", columnDefinition = "TEXT")
    private String auditComment;

    /**
     * 审核标签（JSON格式）
     */
    @Column(name = "audit_tags", columnDefinition = "TEXT")
    private String auditTags;

    /**
     * 创建者ID
     */
    @Size(max = 50, message = "创建者ID长度不能超过50个字符")
    @Column(name = "created_by", nullable = false, length = 50)
    private String createdBy;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "create_time", nullable = false, updatable = false)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    /**
     * 软删除标识
     */
    @NotNull(message = "软删除标识不能为空")
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    private LocalDateTime deleteTime;

    /**
     * 更新人
     */
    @Size(max = 50, message = "更新人长度不能超过50个字符")
    @Column(name = "updated_by", nullable = false, length = 50)
    private String updatedBy;

}